<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
span.s1 {color: #0000bf}
span.s2 {color: #000000}
span.s3 {color: #606060}
span.s4 {color: #007300}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>Getenv<span class="Apple-tab-span">	</span>Read (numeric) shell environment variables into a synth</b></p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>Getenv(key, defaultval)</b></p>
<p class="p2"><br></p>
<p class="p3">Tries to grab a shell environment variable (with name <b>key</b>) and convert it to a floating-point value, which is output.</p>
<p class="p2"><br></p>
<p class="p3">If the environment variable is not set, <b>defaultval</b> is output.</p>
<p class="p3">If the environment variable cannot be converted to a floating-point value, the output is zero.</p>
<p class="p2"><br></p>
<p class="p3">NOTE: the shell context is that of the server, not the client.</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p4"><span class="s1">Server</span><span class="s2">.local.quit; </span>// If server running, need to stop it for this example</p>
<p class="p5"><br></p>
<p class="p4">// We'll modify the server boot procedure to set our env var...</p>
<p class="p6">~realserverprogram = <span class="s1">Server</span>.program;</p>
<p class="p6"><span class="s1">Server</span>.program = <span class="s3">"export PANCREAS=220;"</span> + <span class="s1">Server</span>.program</p>
<p class="p6">s.boot;</p>
<p class="p5"><br></p>
<p class="p6">(</p>
<p class="p6">x = {</p>
<p class="p4"><span class="s2"><span class="Apple-tab-span">	</span></span>// Env var specifies frequency.</p>
<p class="p4"><span class="s2"><span class="Apple-tab-span">	</span></span>// If you change the env var name to one that isn't set, 440 is used.</p>
<p class="p6"><span class="Apple-tab-span">	</span><span class="s1">SinOsc</span>.ar(<span class="s1">Getenv</span>(<span class="s4">\PANCREAS</span>, 440), 0, 0.1);</p>
<p class="p6">}.play(<span class="s1">Server</span>.local);</p>
<p class="p6">)</p>
<p class="p6">x.free;</p>
<p class="p5"><br></p>
<p class="p4">// This should restore the variable to what it was</p>
<p class="p6"><span class="s1">Server</span>.program = ~realserverprogram;</p>
</body>
</html>
